import { Component } from '@angular/core';

declare var $: any;

@Component({
	moduleId: module.id,
	selector: 'dx-framework',
	templateUrl: 'framework.component.html',
	styleUrls: ['./framework.component.css']
})
export class FrameworkComponent {

    heroes1:any[] = [];
    heroes2:any[] = [];
    display_data = [
            {
                'name': '企业组织机构',
                'class': 'fa-group',
                'bool': true,
                'n': 0,
                'href': 'companyInfo/organization',
                'style': 'fa-star-o'
            },
            {
                'name': '岗位管理',
                'class': 'fa-group',
                'bool': true,
                'n': 1,
                'href': 'companyInfo/postmangement',
                'style': 'fa-star-o'
            },
            {
                'name': '职员管理',
                'class': 'fa-group',
                'bool': true,
                'n': 2,
                'href': 'companyInfo/personneladmin',
                'style': 'fa-star-o'
            },
            {
                'name': '应用管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 3,
                'href': 'powerManage/applicatemanage',
                'style': 'fa-star-o'
            },
            {
                'name': '资源管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 4,
                'href': 'powerManage/sourcemanage',
                'style': 'fa-star-o'
            },
            {
                'name': '角色管理',
                'class': 'fa-group',
                'bool': true,
                'n': 5,
                'href': 'powerManage/rolemanage',
                'style': 'fa-star-o'
            },
            {
                'name': '树形角色管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 6,
                'href': 'powerManage/TreeRoleManageComponent',
                'style': 'fa-star-o'
            },
            {
                'name': '通用角色层次',
                'class': 'fa-institution',
                'bool': true,
                'n': 7,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '角色权限分配',
                'class': 'fa-institution',
                'bool': true,
                'n': 8,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '部门岗位权限分配',
                'class': 'fa-institution',
                'bool': true,
                'n': 9,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '代码登记表管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 10,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '非树形编码表管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 11,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '树形编码表管理',
                'class': 'fa-group',
                'bool': true,
                'n': 12,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '回收站',
                'class': 'fa-institution',
                'bool': true,
                'n': 13,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '系统配置参数',
                'class': 'fa-institution',
                'bool': true,
                'n': 14,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '系统日志',
                'class': 'fa-institution',
                'bool': true,
                'n': 15,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '系统异常',
                'class': 'fa-institution',
                'bool': true,
                'n': 16,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '通知-收件箱',
                'class': 'fa-institution',
                'bool': true,
                'n': 17,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '通知-发件箱',
                'class': 'fa-institution',
                'bool': true,
                'n': 18,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '发通知',
                'class': 'fa-institution',
                'bool': true,
                'n': 19,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '访问白名单',
                'class': 'fa-institution',
                'bool': true,
                'n': 20,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '访问黑名单',
                'class': 'fa-institution',
                'bool': true,
                'n': 21,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '个人白名单',
                'class': 'fa-institution',
                'bool': true,
                'n': 22,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '个人黑名单',
                'class': 'fa-institution',
                'bool': true,
                'n': 23,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '岗位管理-共享',
                'class': 'fa-institution',
                'bool': true,
                'n': 24,
                'href': 'companyInfo/postmanagementshare',
                'style': 'fa-star-o'
            },
            {
                'name': '岗位关系树',
                'class': 'fa-institution',
                'bool': true,
                'n': 25,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '职员管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 26,
                'href': 'companyInfo/postmanagement',
                'style': 'fa-star-o'
            },
            {
                'name': '用户组管理',
                'class': 'fa-institution',
                'bool': true,
                'n': 27,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '职员增加',
                'class': 'fa-institution',
                'bool': true,
                'n': 28,
                'href': 'companyInfo/postmanagementadd',
                'style': 'fa-star-o'
            },
            {
                'name': '创建账号',
                'class': 'fa-institution',
                'bool': true,
                'n': 29,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '部门职员分布图',
                'class': 'fa-institution',
                'bool': true,
                'n': 30,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '岗位职员分布图',
                'class': 'fa-institution',
                'bool': true,
                'n': 31,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '职员回收站',
                'class': 'fa-institution',
                'bool': true,
                'n': 32,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '找回密码',
                'class': 'fa-institution',
                'bool': true,
                'n': 33,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '教师注册页',
                'class': 'fa-institution',
                'bool': true,
                'n': 34,
                'href': '',
                'style': 'fa-star-o'
            },
            {
                'name': '学生注册页',
                'class': 'fa-institution',
                'bool': true,
                'n': 35,
                'href': '',
                'style': 'fa-star-o'
            }
        ];
    chevron_down:any[] = [
        {
            'name': '主页',
            'class': 'chevron_down_ul_span_active',
            'n':0
        },
    ];
    Chevron_down = function () {
        if ($('.nav-browse-history-ul').css('display') == 'none') {
            $('.nav-browse-history-ul').css({ 'display': 'block' });
            if (!$('#more').hasClass('click-display1')) {
                $('#more').addClass('click-display1');
            }
            if ($('.control-sidebar').hasClass('control-sidebar-open')) {
                $('.control-sidebar').removeClass('control-sidebar-open');
            }
            if (!$('#newConstruction').hasClass('click-display1')) {
                $('#newConstruction').addClass('click-display1');
            };
        } else {
            $('.nav-browse-history-ul').css({ 'display': 'none' });
        }
    };
    topDelete = function (j:number) {
        if (this.chevron_down.length > 1) {
            this.chevron_down.splice(j, 1);
            this.chevron_down[0].class = 'chevron_down_ul_span_active';
        }
        else if (this.chevron_down[j].n == 0) {
            console.log("当前是浏览的页面不可以删除");
        }
    };
    click_add = function (k: number, name: string) {
        this.chevron_down.unshift({ 'name': this.heroes1[k].name,'class': 'chevron_down_ul_span_active','n':0 });
        this.chevron_down[1].class = '';
        this.chevron_down[1].n = '1';
        if (this.chevron_down.length > 5) {
            this.chevron_down.splice(5,1);
        }
    };
    controlSidebar = function () {
        var ScWidth = $(window).width();
        if ($('.control-sidebar').hasClass('control-sidebar-open')) {
            $('.control-sidebar').removeClass('control-sidebar-open');
        }else {
            $('.control-sidebar').addClass('control-sidebar-open');
            if (ScWidth <= 768) {
                $("body").removeClass('sidebar-collapse');
            };
            if (!$('#newConstruction').hasClass('click-display1')) {
                $('#newConstruction').addClass('click-display1');
            };
            if ($('.nav-browse-history-ul').css('display') != 'none') {
                $('.nav-browse-history-ul').css({ 'display': 'none' });
            };
            if (!$('#more').hasClass('click-display1')) {
                $('#more').addClass('click-display1');
            }
        }
    }; 
    onClickMe = function () {
        if ($('#more').hasClass('click-display1')) {
            $('#more').removeClass('click-display1');
            if (!$('#newConstruction').hasClass('click-display1')) {
                $('#newConstruction').addClass('click-display1');
            };
            if ($('.control-sidebar').hasClass('control-sidebar-open')) {
                $('.control-sidebar').removeClass('control-sidebar-open');
            }
            if ($('.nav-browse-history-ul').css('display') != 'none') {
                $('.nav-browse-history-ul').css({ 'display': 'none' });
            }
        }
        else {
            $('#more').addClass('click-display1');
        }
    };
    onClickMeTwo = function () {
        if ($('#newConstruction').hasClass('click-display1')) {
            $('#newConstruction').removeClass('click-display1');
            if (!$('#more').hasClass('click-display1')) {
                $('#more').addClass('click-display1');
            }
            if ($('.control-sidebar').hasClass('control-sidebar-open')) {
                $('.control-sidebar').removeClass('control-sidebar-open');
            }
            if ($('.nav-browse-history-ul').css('display') != 'none') {
                $('.nav-browse-history-ul').css({ 'display': 'none' });
            }
        }
        else {
            $('#newConstruction').addClass('click-display1');
        }
    };
    clickLocation = function (i:number) {
        if (this.display_data[i].bool) {
            this.display_data[i].bool = false;
            var x = { 'name': this.display_data[i].name, 'class': this.display_data[i].class, 'n': this.display_data[i].n, 'href': this.display_data[i].href, 'bool': this.display_data[i].bool };
            this.heroes1.push(x);
            this.display_data[i].style = "display-red fa-star";
            var z = '{"name":"' + this.display_data[i].name + '","class":"' + this.display_data[i].class + '","n":"' + this.display_data[i].n + '","href":"' + this.display_data[i].href + '"}';
            this.heroes2.push(z);
            if (window.localStorage){
                localStorage.setItem("localName", JSON.stringify(this.heroes2));
            } else {
                $.cookie('cookieName', JSON.stringify(this.heroes2), { expires: 7 });
            }
        }
        else {
            for (var j = 0; j <= this.heroes1.length; j++) {
                if (this.heroes1[j].n == this.display_data[i].n) {
                    this.display_data[i].bool = true;
                    this.heroes1.splice(j, 1);
                    this.heroes2.splice(j, 1);
                    this.display_data[i].style = 'fa-star-o';
                    break;
                }
            }
            if (window.localStorage) {
                localStorage.setItem("localName", JSON.stringify(this.heroes2));
            } else {
                $.cookie('cookieName', JSON.stringify(this.heroes2), { expires: 7 });
            }
        }
    };
    bottomSurface = function (i: number) {
        $('.click-display-foot span').html(this.display_data[i].name);        
    };
    ngOnInit() {
        $(window).ready(function () {
            var ScreenWidth = $(window).width();
            var ScreenHeight = $(window).height();
            var ScrollSidebarMenu: any, hidden_ul: any, ContentHeight: any;
            if(ScreenWidth <= 768) {
                ScrollSidebarMenu = ScreenHeight-255;
                hidden_ul = ScreenHeight-278;
                ContentHeight = ScreenHeight;
                $('.scroll-sidebar-menu').slimScroll({ height: ScrollSidebarMenu + 'px'});
                $('.hidden-ul').slimScroll({height: hidden_ul+'px'});
                $('.content-wrapper').css({'min-height':ContentHeight+'px'});
            }else{
                ScrollSidebarMenu = ScreenHeight-195;
                hidden_ul = ScreenHeight-218;
                ContentHeight = ScreenHeight;
                $('.scroll-sidebar-menu').slimScroll({ height: ScrollSidebarMenu+'px'});
                $('.hidden-ul').slimScroll({height: hidden_ul+'px'});
                $('.content-wrapper').css({'min-height':ContentHeight+'px'});
            }
        })
        if ($("body").hasClass('sidebar-collapse')) {
            $(".main-sidebar").tooltip({
                items: "[title]",
                content: function () {
                    var element = $(this);
                    if (element.is("[title]")) {
                        return element.attr("title");
                    }
                },
                position: {
                    my: "left+15 center", at: "right center",
                    using: function (position:any) {
                        $(this).css(position);
                        $("<div>")
                            .addClass("arrow")
                            .appendTo(this);
                    }
                }
            });
        }
		$(window).resize(function () {  
		    var SlideScreenHeight = $(window).height();
            var SlideScreenWidth = $(window).width();
            var hidden_ul: any, ScrollSidebarMenu: any, ContentHeight: any;
            if(SlideScreenWidth <= 768) {
                hidden_ul = SlideScreenHeight - 278;
                ScrollSidebarMenu = SlideScreenHeight - 255;
                ContentHeight = SlideScreenHeight;
                $('.hidden-ul').slimScroll({ height: hidden_ul + 'px' });
                $('.scroll-sidebar-menu').slimScroll({ height: ScrollSidebarMenu + 'px' });
                $('.content-wrapper').css({ 'min-height': ContentHeight + 'px' }); ;    
            }else{
                hidden_ul = SlideScreenHeight - 218;
                ScrollSidebarMenu = SlideScreenHeight - 195;
                ContentHeight = SlideScreenHeight;
                $('.hidden-ul').slimScroll({ height: hidden_ul + 'px' });
                $('.scroll-sidebar-menu').slimScroll({ height: ScrollSidebarMenu + 'px' });
                $('.content-wrapper').css({ 'min-height': ContentHeight + 'px' });    
            }
		})
        $(".color-span").click(function () {
            console.log(123);
            if ($(this).attr('name') == 1) {
                localStorage.removeItem("BgColor");
                $('.sidebar-mini').removeClass('skin-white-light');
                $('.sidebar-mini').removeClass('skin-black-light');
                $('.sidebar-mini').addClass('skin-blue-light');
                if (window.localStorage) {
                    localStorage.setItem("BgColor", '1');
                } else {
                    $.cookie('BgColor', '1');
                }
            }else if($(this).attr('name') == 2){
                localStorage.removeItem("BgColor");
                $('.sidebar-mini').removeClass('skin-blue-light');
                $('.sidebar-mini').removeClass('skin-black-light');
                $('.sidebar-mini').addClass('skin-white-light');
                if (window.localStorage) {
                    localStorage.setItem("BgColor", '2');
                } else {
                    $.cookie('BgColor', '2');
                }
            }else{
                localStorage.removeItem("BgColor");
                $('.sidebar-mini').removeClass('skin-white-light');
                $('.sidebar-mini').removeClass('skin-blue-light');
                $('.sidebar-mini').addClass('skin-black-light');
                if (window.localStorage) {
                    localStorage.setItem("BgColor", '3');
                } else {
                    $.cookie('BgColor', '3');
                }
            }
        })
        $(".content-wrapper").click(function () {
            if (!$('#more').hasClass('click-display1')) {
                $('#more').addClass('click-display1');
            };
            if ($('.control-sidebar').hasClass('control-sidebar-open')) {
                $('.control-sidebar').removeClass('control-sidebar-open');
            };
            if ($('.nav-browse-history-ul').css('display') != 'none') {
                $('.nav-browse-history-ul').css({ 'display': 'none' });
            };
            if (!$('#newConstruction').hasClass('click-display1')) {
                $('#newConstruction').addClass('click-display1');
            };
        });
        $(".scroll-sidebar-menu").click(function () {
            if (!$('#more').hasClass('click-display1')) {
                $('#more').addClass('click-display1');
            };
            if ($('.control-sidebar').hasClass('control-sidebar-open')) {
                $('.control-sidebar').removeClass('control-sidebar-open');
            };
            if ($('.nav-browse-history-ul').css('display') != 'none') {
                $('.nav-browse-history-ul').css({ 'display': 'none' });
            };
            if (!$('#newConstruction').hasClass('click-display1')) {
                $('#newConstruction').addClass('click-display1');
            };
        });
        var json: any,bgcolor:any;
        if (localStorage.getItem("BgColor") == undefined) {
            console.log('数据为空');
        } else {
            bgcolor = localStorage.getItem("BgColor");
            if (bgcolor == 1){
                $('.sidebar-mini').removeClass('skin-white-light');
                $('.sidebar-mini').removeClass('skin-black-light');
                $('.sidebar-mini').addClass('skin-blue-light');
            } else if (bgcolor == 2){
                $('.sidebar-mini').removeClass('skin-blue-light');
                $('.sidebar-mini').removeClass('skin-black-light');
                $('.sidebar-mini').addClass('skin-white-light');
            } else {
                $('.sidebar-mini').removeClass('skin-white-light');
                $('.sidebar-mini').removeClass('skin-blue-light');
                $('.sidebar-mini').addClass('skin-black-light');
            }
        }
        if (localStorage.getItem("Folde") == undefined) {
            console.log('数据为空');
        } else {
            $('body').addClass(localStorage.getItem("Folde"));
            $('.click-display').css({ 'left': '60px' });
        }
        if (window.localStorage) {
            localStorage.getItem("localName")
            json = eval('(' + localStorage.getItem("localName") + ')');
        } else {
            json = eval('(' + $.cookie('cookieName') + ')');
        };
        if (json == undefined) {
            console.log("数据为空");
        }else {
            for (var j = 0; j < json.length; j++) {
                this.heroes1.push($.parseJSON(json[j]));
                this.heroes2.push(json[j]);
                this.display_data[$.parseJSON(json[j]).n].bool = !$.parseJSON(json[j]).n;
                this.display_data[$.parseJSON(json[j]).n].style = "display-red fa-star";
            }
        }
    }
}